/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UIDistribucionEmpirica.java
 *
 * Created on 07/06/2010, 11:59:43
 */

package vista;

import distribuciones.Empirica;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableColumn;
import vista.util.UIDistribucionEmpiricaUtil;
import vista.util.UIVentanaPrincipalUtil;

/**
 *
 * @author Carolina
 */
public class UIDistribucionEmpirica extends javax.swing.JFrame
{

    private UIDistribucionEmpiricaUtil util = new UIDistribucionEmpiricaUtil();
    private UIVentanaPrincipalUtil principalUtil;
    private Vector intervaloFrecuencia = new Vector();
    private Vector intervaloNoFrecuencia = new Vector();
    private Vector rFrec = new Vector();
    private Vector rNoFrec = new Vector();
    private Vector r = new Vector();
    private Vector x = new Vector();
    private Vector a = new Vector();
    private Empirica empirica = new Empirica();

    /** Creates new form UIDistribucionEmpirica */
    public UIDistribucionEmpirica() {
        initComponents();
    }

    public UIDistribucionEmpirica(UIVentanaPrincipalUtil principalUtil)
    {
//        this.principalUtil = new UIVentanaPrincipalUtil();
        this.principalUtil = principalUtil;
        initComponents();
        this.inicializar();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableConFrecuencia = new javax.swing.JTable();
        jTextFieldIntervalo = new javax.swing.JTextField();
        jButtonCargar = new javax.swing.JButton();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableSinFrecuencia = new javax.swing.JTable();
        jTextFieldIntervalo1 = new javax.swing.JTextField();
        jButtonCargar1 = new javax.swing.JButton();
        jButtonGenerar = new javax.swing.JButton();
        jButtonSalir = new javax.swing.JButton();
        jTextFieldCantidad = new javax.swing.JTextField();
        jTextFieldNombre = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Distribucion Empirica");
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Con frecuencia relativa"));

        jTableConFrecuencia.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Intervalo", "Frecuencia", "Frec. Rel.", "Frec. Acumulada"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableConFrecuencia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTableConFrecuenciaKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTableConFrecuencia);

        jTextFieldIntervalo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldIntervaloKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldIntervaloKeyReleased(evt);
            }
        });

        jButtonCargar.setText("Cargar");
        jButtonCargar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCargarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 596, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(182, 182, 182)
                        .addComponent(jTextFieldIntervalo, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonCargar, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldIntervalo, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCargar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        buttonGroup.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Obtener numeros aleatorios con distribucion empirica conociendo la frecuencia relativa");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        buttonGroup.add(jRadioButton2);
        jRadioButton2.setText("Obtener numeros aleatorios con distribucion empirica sin conocer la frecuencia relativa");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Sin frecuencia relativa"));

        jTableSinFrecuencia.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Intervalo", "Probabilidad", "Prob. Acumulada"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Double.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jTableSinFrecuencia);

        jTextFieldIntervalo1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldIntervalo1KeyReleased(evt);
            }
        });

        jButtonCargar1.setText("Cargar");
        jButtonCargar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCargar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(182, 182, 182)
                        .addComponent(jTextFieldIntervalo1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonCargar1, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 596, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldIntervalo1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCargar1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonGenerar.setText("Generar");
        jButtonGenerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGenerarActionPerformed(evt);
            }
        });

        jButtonSalir.setText("Salir");
        jButtonSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSalirActionPerformed(evt);
            }
        });

        jTextFieldCantidad.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldCantidadKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextFieldCantidadKeyReleased(evt);
            }
        });

        jLabel1.setText("Nombre de la variable");

        jLabel2.setText("Cantidad");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jRadioButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 644, Short.MAX_VALUE)
                    .addComponent(jRadioButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 644, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTextFieldNombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE))
                        .addGap(35, 35, 35)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTextFieldCantidad, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                        .addComponent(jButtonGenerar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonSalir)
                    .addComponent(jButtonGenerar))
                .addGap(21, 21, 21))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonGenerarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonGenerarActionPerformed
    {//GEN-HEADEREND:event_jButtonGenerarActionPerformed
        // TODO add your handling code here:
        this.generar();
//        this.ajustarTamanioColumna();
    }//GEN-LAST:event_jButtonGenerarActionPerformed

    private void jButtonSalirActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonSalirActionPerformed
    {//GEN-HEADEREND:event_jButtonSalirActionPerformed
        // TODO add your handling code here:
        this.limpiarTodo();
        this.dispose();
    }//GEN-LAST:event_jButtonSalirActionPerformed

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jRadioButton1ActionPerformed
    {//GEN-HEADEREND:event_jRadioButton1ActionPerformed
        // TODO add your handling code here:
        this.habilitarDeshabilitar();
        this.jTextFieldIntervalo.requestFocus();
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jRadioButton2ActionPerformed
    {//GEN-HEADEREND:event_jRadioButton2ActionPerformed
        // TODO add your handling code here:
        this.habilitarDeshabilitar();
        this.jTextFieldIntervalo1.requestFocus();
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jButtonCargarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCargarActionPerformed
    {//GEN-HEADEREND:event_jButtonCargarActionPerformed
        // TODO add your handling code here:
        this.cargar("FRECUENCIA");
    }//GEN-LAST:event_jButtonCargarActionPerformed

    private void jButtonCargar1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCargar1ActionPerformed
    {//GEN-HEADEREND:event_jButtonCargar1ActionPerformed
        // TODO add your handling code here:
        this.cargar("SIN");
    }//GEN-LAST:event_jButtonCargar1ActionPerformed

    private void jTableConFrecuenciaKeyReleased(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTableConFrecuenciaKeyReleased
    {//GEN-HEADEREND:event_jTableConFrecuenciaKeyReleased
        // TODO add your handling code here:
        if(evt.getKeyCode() == 10)
        {
            this.rFrec = this.util.calcularFrecuencias(this.jTableConFrecuencia);
        }
    }//GEN-LAST:event_jTableConFrecuenciaKeyReleased

    private void jTextFieldIntervaloKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldIntervaloKeyPressed
    {//GEN-HEADEREND:event_jTextFieldIntervaloKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldIntervaloKeyPressed

    private void jTextFieldIntervaloKeyReleased(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldIntervaloKeyReleased
    {//GEN-HEADEREND:event_jTextFieldIntervaloKeyReleased
        // TODO add your handling code here:
        if(evt.getKeyCode() == 10)
        {
            this.cargar("FRECUENCIA");
        }
    }//GEN-LAST:event_jTextFieldIntervaloKeyReleased

    private void jTextFieldIntervalo1KeyReleased(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldIntervalo1KeyReleased
    {//GEN-HEADEREND:event_jTextFieldIntervalo1KeyReleased
        // TODO add your handling code here:
        if(evt.getKeyCode() == 10)
        {
            this.cargar("SIN");
        }
    }//GEN-LAST:event_jTextFieldIntervalo1KeyReleased

    private void jTextFieldCantidadKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldCantidadKeyPressed
    {//GEN-HEADEREND:event_jTextFieldCantidadKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCantidadKeyPressed

    private void jTextFieldCantidadKeyReleased(java.awt.event.KeyEvent evt)//GEN-FIRST:event_jTextFieldCantidadKeyReleased
    {//GEN-HEADEREND:event_jTextFieldCantidadKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldCantidadKeyReleased

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new UIDistribucionEmpirica().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JButton jButtonCargar;
    private javax.swing.JButton jButtonCargar1;
    private javax.swing.JButton jButtonGenerar;
    private javax.swing.JButton jButtonSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTableConFrecuencia;
    private javax.swing.JTable jTableSinFrecuencia;
    private javax.swing.JTextField jTextFieldCantidad;
    private javax.swing.JTextField jTextFieldIntervalo;
    private javax.swing.JTextField jTextFieldIntervalo1;
    private javax.swing.JTextField jTextFieldNombre;
    // End of variables declaration//GEN-END:variables

    private void inicializar()
    {
        this.ajustarTamanioColumna();
        this.centrar();
        this.habilitarDeshabilitar();
        this.jTextFieldIntervalo.requestFocus();
    }

    private void centrar()
    {
        Dimension pantalla, cuadro;
	pantalla = Toolkit.getDefaultToolkit().getScreenSize();
	cuadro = this.getSize();
	this.setLocation(((pantalla.width - cuadro.width)/2), (pantalla.height - cuadro.height)/2);
    }


    private void ajustarTamanioColumna()
    {
        TableColumn column = null;
        for (int i = 0; i < 4; i++)
        {
            column = jTableConFrecuencia.getColumnModel().getColumn(i);
            switch(i)
            {
                case 0:
                        column.setPreferredWidth(183);
//                        System.out.println("El tamaño de la clumna 1 es: "+column.getPreferredWidth());
                        break;
                case 1:
                        column.setPreferredWidth(39);
//                        System.out.println("El tamaño de la clumna 1 es: "+column.getPreferredWidth());
                        break;
                case 2:
                        column.setPreferredWidth(39);
//                        System.out.println("El tamaño de la clumna 1 es: "+column.getPreferredWidth());
                        break;
                case 3:
                        column.setPreferredWidth(39);
//                        System.out.println("El tamaño de la clumna 1 es: "+column.getPreferredWidth());
//                        column.setPreferredWidth(37);
                        break;
            }
        }

        for (int i = 0; i < 3; i++)
        {
            column = jTableSinFrecuencia.getColumnModel().getColumn(i);
            switch(i)
            {
                case 0:
                        column.setPreferredWidth(202);
//                        System.out.println("El tamaño de la clumna 1 es: "+column.getPreferredWidth());
                        break;
                case 1:
                        column.setPreferredWidth(15);
//                        System.out.println("El tamaño de la clumna 1 es: "+column.getPreferredWidth());
                        break;
                case 2:
                        column.setPreferredWidth(15);
//                        System.out.println("El tamaño de la clumna 1 es: "+column.getPreferredWidth());
                        break;
            }
        }
    }


    private void habilitarDeshabilitar()
    {
        if(this.jRadioButton1.isSelected())
        {
            this.util.habilitar(this.jTableConFrecuencia, this.jTextFieldIntervalo, this.jButtonCargar);
            this.util.deshabilitar(this.jTableSinFrecuencia, this.jTextFieldIntervalo1, this.jButtonCargar1);
        }
        else
        {
            this.util.habilitar(this.jTableSinFrecuencia, this.jTextFieldIntervalo1, this.jButtonCargar1);
            this.util.deshabilitar(this.jTableConFrecuencia, this.jTextFieldIntervalo, this.jButtonCargar);
        }
    }

    private void cargar(String vec)
    {

        if(vec.equals("FRECUENCIA"))
        {
            if(this.util.validar(this.jTextFieldIntervalo))
            {
                
                this.intervaloFrecuencia = this.util.cargar(this.intervaloFrecuencia, this.jTextFieldIntervalo , this.jTableConFrecuencia, true);
                this.jTextFieldIntervalo.setText("");
                this.jTextFieldIntervalo.requestFocus();
            }
        }
        else
            if(this.util.validar(this.jTextFieldIntervalo1))
            {
                this.intervaloNoFrecuencia = this.util.cargar(this.intervaloNoFrecuencia, this.jTextFieldIntervalo1, this.jTableSinFrecuencia, false);
                this.rNoFrec = this.util.generarProbabilidades(this.jTableSinFrecuencia);
                this.jTextFieldIntervalo1.setText("");
                this.jTextFieldIntervalo1.requestFocus();
            }
    }

    private void generar()
    {
        if(this.util.validar(this.jTextFieldNombre, this.jTextFieldCantidad, this.jTableConFrecuencia, this.jTableSinFrecuencia, this.jRadioButton1.isSelected()))
        {
            if(this.jRadioButton1.isSelected())
            {
                this.r =this.rFrec;
                this.x = this.intervaloFrecuencia;
            }
            else
            {
                this.r = this.rNoFrec;
                this.x = this.intervaloNoFrecuencia;
            }
            this.a = this.util.calcularPendiente(r, x);
            this.empirica.setA(this.util.convertVectorToDouble(a));
            this.empirica.setR(this.util.convertVectorToDouble(r));
            this.empirica.setX(this.util.convertVectorToDouble(x));
            this.principalUtil.cargarEmpirica(empirica, this.jTextFieldNombre.getText(), Integer.parseInt(this.jTextFieldCantidad.getText()));
            this.limpiarTodo();
            this.dispose();
        }

     }

    private void limpiarTodo()
    {
        //limpiando las tablas
        this.util.limpiar(this.jTableConFrecuencia);
        this.util.limpiar(this.jTableSinFrecuencia);

        //limpiando los JTextField
        this.jTextFieldCantidad.setText("");
        this.jTextFieldIntervalo.setText("");
        this.jTextFieldIntervalo1.setText("");
        this.jTextFieldNombre.setText("");

        //vaciando los vectores
        this.intervaloFrecuencia.clear();
        this.intervaloNoFrecuencia.clear();
        this.rFrec.clear();
        this.rNoFrec.clear();
        this.x.clear();
        this.a.clear();
        this.r.clear();
    }

}
